//
//  StudioHeaderView.m
//  Arts1
//
//  Created by 孤星晨宇 on 15/9/15.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "StudioHeaderView.h"
#import "UIViewAdditions.h"
#import "AllHeader.h"
#import <UIImageView+WebCache.h>

@interface StudioHeaderView ()

@property (nonatomic ,assign) int status;

@end

@implementation StudioHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        UIView *backgroundView = [[UIView alloc] initWithFrame:self.bounds];
        backgroundView.backgroundColor = [UIColor whiteColor];
        [self addSubview:backgroundView];
        [UIView viewWideForShadowColor:backgroundView];
        
        UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
        line1.alpha = 0.5;
        line1.backgroundColor = kCustomColor(150, 150, 150, 1);
        [self addSubview:line1];
        
        _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 13, 48, 48)];
//        _iconView.image = [UIImage imageNamed:@"7.jpeg"];
        _iconView.backgroundColor = kRandomColor;
        _iconView.layer.cornerRadius = 24;
        _iconView.layer.masksToBounds = YES;
        [self addSubview:_iconView];
        
        _collegeName = [[UILabel alloc] initWithFrame:CGRectMake(_iconView.right + 10, 20, 160, 18)];
//        _collegeName.text = @"东方画室";
        _collegeName.font = [UIFont systemFontOfSize:16];
        [self addSubview:_collegeName];
        
        _followLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconView.right + 10 , _collegeName.bottom + 2, 50, 15)];
//        _followLabel.text = @"关注：200";
        _followLabel.font = [UIFont boldSystemFontOfSize:10];
        _followLabel.textColor = kCustomColor(150, 150, 150, 1);
        [self addSubview:_followLabel];
        
        _bookNum = [[UILabel alloc] initWithFrame:CGRectMake(_followLabel.right + 5, _followLabel.top, 50, 15)];
//        _bookNum.text = @"报名：1923";
        _bookNum.font = [UIFont boldSystemFontOfSize:10];
        _bookNum.textColor = kCustomColor(150, 150, 150, 1);
        [self addSubview:_bookNum];
        
        _attentionBTN = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _attentionBTN.frame = CGRectMake(SCREEN_WIDTH - 80 , 24 , 70 , 28 );
        _attentionBTN.titleLabel.font = [UIFont systemFontOfSize:13];
        _attentionBTN.layer.cornerRadius = 4;
        _attentionBTN.layer.masksToBounds = YES;
        [_attentionBTN setTitle:@"关注" forState:(UIControlStateNormal)];
        _attentionBTN.backgroundColor = kCustomColor(50, 50, 70, 1);
        [self addSubview:_attentionBTN];
        
        UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, 74, SCREEN_WIDTH, 0.5)];
        line2.alpha = 0.5;
        line2.backgroundColor = kCustomColor(150, 150, 150, 1);
        [self addSubview:line2];

        
        [self createButtons];
    }
    return self;
}

// 循环创建button---- @"最新动态",@"招生简章",@"成绩查询",@"历年考题"
- (void)createButtons{
    NSArray *arr = @[@"最新动态",@"课程安排",@"优秀作品",@"联系我们"];
    
    for (int i = 0; i < 4; i++) {
        UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        btn.frame = CGRectMake(i * SCREEN_WIDTH /4.0 + 17, _iconView.bottom + 18, 60, 30);
        btn.tag = 100 + i;
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        if (i == 0) {
            [btn setTitleColor:lFONTCOLOR forState:(UIControlStateNormal)];
        } else {
            [btn setTitleColor:sFONTCOLOR forState:(UIControlStateNormal)];
        }
        [btn setTitle:arr[i] forState:(UIControlStateNormal)];
        [btn addTarget:self action:@selector(enterNextView:) forControlEvents:(UIControlEventTouchUpInside)];
        [self addSubview:btn];
    }
    
    for (int i = 1; i < 4; i ++) {
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(i * SCREEN_WIDTH /4.0 , _iconView.bottom + 23 , 0.5, 20)];
        line.backgroundColor = kCustomColor(150, 150, 150, 1);
        line.alpha = 0.5;
        [self addSubview:line];
    }
    
}

//  关注
- (void)buttonStatus:(NSNotification *)buttonStatus{
    //已经关注
    //    if (_status) {
    
    NSLog(@"%@",buttonStatus.object);
    _status = [buttonStatus.object intValue];
    
    if (_status) {
        [_attentionBTN setTitle:@"取消关注" forState:(UIControlStateNormal)];
        _status = 0;
    }
    else
    {
        [_attentionBTN setTitle:@"关注" forState:(UIControlStateNormal)];
        _status = 1;
    }
    //    }
}

// 重写setter方法，给控件赋值
- (void)setStudio:(SSDetailModel *)studio{
    _studio = studio;
    _collegeName.text = _studio.spaceName;
    _followLabel.text = [NSString stringWithFormat:@"关注:%@",_studio.comments];
    _bookNum.text = [NSString stringWithFormat:@"报名:%@",_studio.bookNum];
    [_iconView sd_setImageWithURL:[NSURL URLWithString:_studio.headImg]];
    
}

- (void)enterNextView:(UIButton *)btn{
    NSInteger index = btn.tag - 100;
    [btn setTitleColor:lFONTCOLOR forState:(UIControlStateNormal)];
    for (int i = 0; i < 4; i ++) {
        if (index != i ) {
            UIButton *button = (UIButton *)[self viewWithTag:100 + i];
            [button setTitleColor:sFONTCOLOR forState:(UIControlStateNormal)];
        }
    }
    if (_changeviewblock) {
        _changeviewblock(index);
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
